package com.centriole.service.workflow.service.impl;

import com.centriole.service.workflow.dao.NoticeMapper;
import com.centriole.service.workflow.entity.Notice;
import com.centriole.service.workflow.enums.StateType;
import com.centriole.service.workflow.service.NoticeService;
import com.centriole.service.workflow.util.CommonUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

	@Resource
	private NoticeMapper noticeMapper;
	
	public void insertNotice(Notice notice) {
		//字段检查
		check(notice);
		
		/*List<Notice> list = noticeMapper.selectByNodeId(notice.getProNodeId());
		if(CommonUtil.isNotEmpty(list)){
			noticeMapper.deleteByNodeId(notice.getProNodeId());
		}*/
		notice.setState(StateType.NORMAL.statusCode());
		notice.setCreateDate(new Date());
		noticeMapper.insertNotice(notice);
	}

	public void logicDeleteByProcessId(String processId) {
		noticeMapper.logicDeleteByProcessId(processId);
	}

	public void deleteByProcessId(String processId) {
		noticeMapper.deleteByProcessId(processId);
	}

	public List<Notice> selectByProcessId(String processId) {
		List<Notice> list = noticeMapper.selectByProcessId(processId);
		return list;
	}

	public Notice selectById(String id) {
		Notice n = noticeMapper.selectById(id);
		return n;
	}
	
	private void check(Notice notice) {
		if(CommonUtil.isNotEmpty(notice.getNoticeReceive())){
			if(CommonUtil.isEmpty(notice.getNoticeTitle())){
				//通知标题不能为空
			}
			if(CommonUtil.isEmpty(notice.getNoticeCount())){
				//通知内容不能为空
			}
		}
	}
}
